Vue.prototype.$http = axios;
axios.defaults.crossDomain = true;
// Vue.prototype.$message = Message
//请求拦截
axios.interceptors.request.use(function (req) {
    // 在发送请求之前做些什么，例如加入token
    let token=getCookie("auth_token");
    if(token){
        req.headers.Authorization=token;
        return req;
    }
    alert('token不存在，请重新登录！');
    // Message({
    //     showClose: true,
    //     message: 'token不存在，请重新登录！',
    //     type: 'warning'
    // });
    window.location.href = "/login.html";
    return;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
axios.interceptors.response.use((response) => {
    if (response && response.data) {
        if (!response.status == 200) {
            //alert("passport登录超时，刷新重新登录");
            window.location.reload();
        } else {
            return response;
        }
    } else {
        return response;
    }
}, function (error) {
    console.log("token失效，请重新登录");
});
// axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
function getCookie(name) {
    var prefix = name + "="
    var start = document.cookie.indexOf(prefix)
    if (start == -1) {
        return null;
    }
    var end = document.cookie.indexOf(";", start + prefix.length)
    if (end == -1) {
        end = document.cookie.length;
    }
    var value = document.cookie.substring(start + prefix.length, end)
    return unescape(value);
}